﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace LangRenGameLib.Times
{
    /// <summary>
    /// 获取时间，通常用于操作延时
    /// </summary>
    class GetPassTime
    {
        /// <summary>
        /// 是否已经到达时间
        /// </summary>
        public bool Finish;

        /// <summary>
        /// 需要延时多久
        /// </summary>
        public int NeedTime;

        /// <summary>
        /// 已经延时了多久
        /// </summary>
        public int ThisTime;

        /// <summary>
        /// 线程
        /// </summary>
        private Thread RunTimeThread;

        public GetPassTime(int MaxTime)
        {
            NeedTime = MaxTime;
            RunTimeThread = new Thread(Run);
        }

        public void Start()
        {
            RunTimeThread.Start();
        }

        public void Run()
        {
            while (true)
            {
                ThisTime++;
                if(NeedTime <= ThisTime)
                {
                    Finish = true;
                    break;
                }
                Thread.Sleep(1000);
            }
        }
    }
}
